# coding=utf-8
# @Time : 2021/10/6 13:10
# @File : text.py
# @Software: PyCharm

import random as rm
import time  as tm



def Ridvan2015Accuracy(a,b,c,d):
    '''

    :param a:
    :param b:
    :param c:
    :param d:
    :return:
    '''
    score=(a+b*(1-a-c)+b+a*(1-b-d))/2
    return score

def Xu2008Accuracy(a,b,c,d):
    '''

    :param a:
    :param b:
    :param c:
    :param d:
    :return:
    '''
    score = a+b+c+d
    return score

def randtest01():

    q=2
    flag=0.001
    score=[0,0]
    Hscore=[0,0]

    while True:
        # ROFNs = getScoreequalRandomtwoq_ROFNs_1(q)        ##使用方案一, 完全随机, 看运气， 有时快有时慢
        ROFNs = getScoreequalRandomtwoq_ROFNs_2(q)          ##使用方案二, 较快
        for i in range(2):
            a=ROFNs[i][0][0]
            b=ROFNs[i][0][1]
            c=ROFNs[i][1][0]
            d=ROFNs[i][1][1]
            score[i] = a+b-c-d
            Hscore[i] =Xu2008Accuracy(a, b, c, d)
        if (abs(Hscore[0] - Hscore[1]) < flag or Hscore[0] == Hscore[1]):
            print("the value is find")
            print(a+b-c-d)
            print(a+b+c+d)
            print(ROFNs)
            break

        tm.sleep(0.001)

    print(score)


def getScoreequalRandomtwoq_ROFNs_1(q):
    '''
    :param q:广义正交的次数
    :return:满足(a+b)-(c+d)相等的随机数
    '''

    exp = 10**3                     ##精度位数，因上面函数中flag为0.001，所以精度为小数点后三位

    twoROFNs=[]
    while True:                     ##[a, b], [c, d] 区间条件隐含 a<=b, c<=d条件
        a1 = rm.randint(0, exp)
        b1 = rm.randint(a1, exp)
        c1 = rm.randint(0, exp)
        d1 = rm.randint(c1, exp)

        a2 = rm.randint(0, exp)
        b2 = rm.randint(a2, exp)
        c2 = rm.randint(0, exp)
        d2 = rm.randint(c2, exp)
        # print(a1, b1, c1, d1, a2, b2, c2, d2)
        if a1+b1-(c1+d1) == a2+b2-(c2+d2):
            # print('成功：', a1, b1, c1, d1, a2, b2, c2, d2)
            twoROFNs.append(([a1/exp, b1/exp], [c1/exp, d1/exp]))
            twoROFNs.append(([a2/exp, b2/exp], [c2/exp, d2/exp]))
            break
        #tm.sleep(0.001)
    return twoROFNs


def getScoreequalRandomtwoq_ROFNs_2(q):
    '''
    :param q:广义正交的次数
    :return:
    '''
    exp = 10**3                       ##精度位数，因上面函数中flag为0.001，所以精度为小数点后三位
    score = rm.randint(0, exp)        ##随机生成一个固定的分数，为避免浮点数精度问题，扩大10**exp倍
                                      ##score = a1+b1-(c1+d1) = a2+b2-(c2+d2)
    twoROFNs=[]
    cnt = 0
    while True:                       ##[a, b], [c, d] 区间条件隐含 a<=b, c<=d条件
        a = rm.randint(0, exp)
        b = rm.randint(a, exp)
        temp = a + b - score          ##temp = c+d = score - a - b >= 0
        if temp < 0:
            continue
        c = rm.randint(0, temp)
        d = temp - c
        if c > exp or d > exp:
            continue
        if c > d:
            c, d = d, c
        # print(a, b, c, d)
        twoROFNs.append(([a/exp, b/exp], [c/exp, d/exp]))
        cnt += 1
        if cnt == 2:
            break
        #tm.sleep(0.001)
    return twoROFNs


if __name__=="__main__":
    # getScoreequalRandomtwoq_ROFNs_2(1)
    print(getScoreequalRandomtwoq_ROFNs_2(2))
    # randtest01()












